package com.nsu.cl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nsu.cl.pojo.Grade;
import com.nsu.cl.service.GradeService;
import com.nsu.cl.mapper.GradeMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author 52618
* @description 针对表【grade(年级表)】的数据库操作Service实现
* @createDate 2023-02-16 14:21:02
*/
@Service
@Transactional
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade>
    implements GradeService{
    @Override
    public IPage<Grade> getGradeByOpr(Page<Grade> pageParam, String name) {

        Page<Grade> page = baseMapper.getInfo(pageParam, name);

        return page;
    }

    @Override
    public Grade getGradeById(Long id) {
        Grade grade = baseMapper.getGradeInfoById(id);
        return grade;
    }

    @Override
    public Grade getGradeByName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if(!StringUtils.isEmpty(name)) {
            queryWrapper.eq("name",name);
        }
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<Grade> getGrades() {
        return baseMapper.getGradeList();
    }
}




